//
//  SINAPhotoPopView.m
//  sinashebao
//
//  Created by  androidlongs on 2017/12/28.
//  Copyright © 2017年  androidlongs. All rights reserved.
//

#import "SINAStudentHomeActivityItemPop.h"
#import "SINACircularBeadUtils.h"
#import "SINACalendarUtils.h"
#import "SINAUiviewClickLiserner.h"

@interface  SINAStudentHomeActivityItemPop ()

//用户头像
@property(strong,nonatomic) UIImageView *userTitleImageView ;

//姓名
@property(strong,nonatomic)  UILabel *userNameLabel;
//系
@property(strong,nonatomic)  UILabel *userClassLabel;
//内容
@property(strong,nonatomic)  UILabel *activityDesLabel;
//地址
@property(strong,nonatomic) UILabel *activityLocationLabel;
//是否以发起邀请
@property(strong,nonatomic) UILabel *isActivityLabel;


//时间地址不同时 的时间与地址
@property(strong,nonatomic) UILabel *otherNextActivityDesLabel;
@property(strong,nonatomic) UILabel *otherNextActivityTimeLabel;

@property(strong,nonatomic) UILabel *myNextActivityDesLabel;
@property(strong,nonatomic) UILabel *myNextActivityTimeLabel;


//再逛一逛
@property(strong,nonatomic) UILabel *cancleUILabel;

@property(strong,nonatomic) UIView *nextSelectLocationView;

//接受
@property(strong,nonatomic) UILabel *selectUILabel;


//0默认 1下一步
@property(nonatomic,assign) NSInteger  currentStatue;

@property(nonatomic,assign) NSInteger  userSex;



//选择的时间
@property(nonatomic,strong) NSString  *activitySelectStartTime;
@property(nonatomic,strong) NSString  *activitySelectEndTime;
//选择的地址
@property(nonatomic,strong) NSString  *activitySelectLocation;

@end

@implementation SINAStudentHomeActivityItemPop

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

-(instancetype)initWithPageType:(NSInteger)pageType {
    self = [super init];
    if (self) {
        self.pageType=pageType;
        
        self.bounds = [UIScreen mainScreen].bounds;
        self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.64];
        self.layer.opacity = 0.0;
        
        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(disMiss)];
        self.userInteractionEnabled = YES;
        [self addGestureRecognizer:tap];
        
        [self addSubview:self.contentView];
        
        self.contentView.frame = CGRectMake(self.contentView.frame.origin.x, self.contentView.frame.origin.y, self.contentView.frame.size.width, self.contentView.frame.size.height);
        //圆角
        [SINACircularBeadUtils makeCircularBead:5 andView:self.contentView];
        
        
        UIImageView *headerImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.contentView.frame), 132)];
        headerImageView.image = [UIImage imageNamed:@""];
        [self.contentView addSubview:headerImageView];
        
      
        headerImageView.image = [UIImage imageNamed:@"person_infor_bg"];
        
        //用户头像
        UIImageView *userTitleImageView = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.contentView.frame)/2-36, 97, 72, 72)];
        userTitleImageView.image = [UIImage imageNamed:@""];
        [self.contentView addSubview:userTitleImageView];
        [SINACircularBeadUtils makeCircularView:userTitleImageView];
        
        self.userTitleImageView = userTitleImageView;
        
        // 用户姓名
        
        UILabel *consigneeUILabel = [[UILabel alloc]initWithFrame:CGRectMake(24,CGRectGetHeight(headerImageView.frame)+50, CGRectGetWidth(self.contentView.frame)-48, 22)];
        consigneeUILabel.text=@"";
        consigneeUILabel.backgroundColor=[UIColor colorWithHexString:@"#eeeeee"];
        consigneeUILabel.textAlignment=NSTextAlignmentCenter;
        consigneeUILabel.font=[UIFont systemFontOfSize:18];
        consigneeUILabel.textColor=[UIColor colorWithHexString:@"#2e2e2e"];
        self.userNameLabel = consigneeUILabel;
        [self.contentView addSubview:consigneeUILabel];
        
        
        //收货地址
        UILabel *consigneeLocationUILabel = [[UILabel alloc]initWithFrame:CGRectMake(24,CGRectGetMaxY(consigneeUILabel.frame)+8, CGRectGetWidth(self.contentView.frame)-48, 22)];
        consigneeLocationUILabel.text=@"";
        consigneeLocationUILabel.backgroundColor=[UIColor colorWithHexString:@"#eeeeee"];
        consigneeLocationUILabel.textAlignment=NSTextAlignmentCenter;
        consigneeLocationUILabel.font=[UIFont systemFontOfSize:14];
        consigneeLocationUILabel.textColor=[UIColor colorWithHexString:@"#2e2e2e"];
        self.userClassLabel = consigneeLocationUILabel;
        [self.contentView addSubview:consigneeLocationUILabel];
        
        
        //内容
        UILabel *activityDes = [[UILabel alloc]initWithFrame:CGRectMake(24,CGRectGetMaxY(consigneeLocationUILabel.frame)+15, CGRectGetWidth(self.contentView.frame)-48, 22)];
        activityDes.text=@"";
        activityDes.backgroundColor=[UIColor colorWithHexString:@"#eeeeee"];
        activityDes.textAlignment=NSTextAlignmentLeft;
        activityDes.font=[UIFont systemFontOfSize:14];
        activityDes.textColor=[UIColor colorWithHexString:@"#2e2e2e"];
        self.activityDesLabel = activityDes;
        [self.contentView addSubview:activityDes];
        
        //地址
        UILabel *activityLocationLabel = [[UILabel alloc]initWithFrame:CGRectMake(24,CGRectGetMaxY(activityDes.frame)+8, CGRectGetWidth(self.contentView.frame)-48, 22)];
        activityLocationLabel.text=@"";
        activityLocationLabel.backgroundColor=[UIColor colorWithHexString:@"#eeeeee"];
        activityLocationLabel.textAlignment=NSTextAlignmentLeft;
        activityLocationLabel.font=[UIFont systemFontOfSize:14];
        activityLocationLabel.textColor=[UIColor colorWithHexString:@"#2e2e2e"];
        self.activityLocationLabel=activityLocationLabel;
        [self.contentView addSubview:activityLocationLabel];
        
        
        //地址
        UILabel *isActivityLabel = [[UILabel alloc]initWithFrame:CGRectMake(24,CGRectGetMaxY(activityLocationLabel.frame)+8, CGRectGetWidth(self.contentView.frame)-48, 22)];
        isActivityLabel.text=@"";
        isActivityLabel.backgroundColor=[UIColor colorWithHexString:@"#eeeeee"];
        isActivityLabel.textAlignment=NSTextAlignmentLeft;
        isActivityLabel.font=[UIFont systemFontOfSize:14];
        isActivityLabel.textColor=[UIColor colorWithHexString:@"#2e2e2e"];
        self.isActivityLabel=isActivityLabel;
        [self.contentView addSubview:isActivityLabel];
        
        
        //再逛一逛
        
        UILabel *cancleUILabel = [[UILabel alloc]initWithFrame:CGRectMake(15,CGRectGetMaxY(isActivityLabel.frame)+48, CGRectGetWidth(self.contentView.frame)/2-25, 32)];
        cancleUILabel.text=@"确认";
        cancleUILabel.textAlignment=NSTextAlignmentCenter;
        cancleUILabel.font=[UIFont systemFontOfSize:16];
        cancleUILabel.textColor=[UIColor colorWithHexString:@"#ffffff"];
        self.cancleUILabel =cancleUILabel;
        [self.contentView addSubview:cancleUILabel];
        [SINACircularBeadUtils makeCircularBead:5 andView:cancleUILabel andIsSetBackground:YES];
        
        
        //接受
        UILabel *selectUILabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.contentView.frame)/2+15,CGRectGetMaxY(isActivityLabel.frame)+48, CGRectGetWidth(self.contentView.frame)/2-30, 32)];
        selectUILabel.text=@"取消";
        selectUILabel.textAlignment=NSTextAlignmentCenter;
        selectUILabel.font=[UIFont systemFontOfSize:16];
        selectUILabel.textColor=[UIColor colorWithHexString:@"#ffffff"];
        
        self.selectUILabel=selectUILabel;
        [self.contentView addSubview:selectUILabel];
        [SINACircularBeadUtils makeCircularBead:5 andView:selectUILabel andIsSetBackground:YES];
        
        
        if (self.pageType==0) {
            //
            selectUILabel.text=@"取消";
            cancleUILabel.text=@"确定";
            cancleUILabel.backgroundColor=[UIColor colorWithHexString:@"#eeeeee"];
        } else {
            selectUILabel.text=@"不同意";
            cancleUILabel.text=@"同意";
        }
        
        CGRect frame =  self.contentView.frame;
        frame.size.height=CGRectGetMaxY(selectUILabel.frame)+20;
        self.contentView.frame = frame;
        
        UIView *nextSelectLocationView = [[UIView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(headerImageView.frame)+68, CGRectGetWidth(self.contentView.frame), 160)];
        nextSelectLocationView.backgroundColor=[UIColor clearColor];
        
        UIView *selectUiview1=[[UIView alloc]initWithFrame:CGRectMake(15, 20, 15, 15)];
        UIImageView *selectImageView =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 15, 15)];
        selectImageView.image=[UIImage imageNamed:@"ask_pass_icon"];
        [selectUiview1 addSubview:selectImageView];
        [nextSelectLocationView addSubview:selectUiview1];
        
        
        UILabel *nextActivityDes1Label = [[UILabel alloc]initWithFrame:CGRectMake(45,0, CGRectGetWidth(self.contentView.frame)-55, 22)];
        nextActivityDes1Label.text=@"";
        nextActivityDes1Label.textAlignment=NSTextAlignmentLeft;
        nextActivityDes1Label.font=[UIFont systemFontOfSize:14];
        nextActivityDes1Label.textColor=[UIColor colorWithHexString:@"#2e2e2e"];
        self.otherNextActivityDesLabel=nextActivityDes1Label;
        
        [nextSelectLocationView addSubview:nextActivityDes1Label];
        
        UILabel *nextLocation1Label = [[UILabel alloc]initWithFrame:CGRectMake(45,CGRectGetMaxY(nextActivityDes1Label.frame)+10, CGRectGetWidth(self.contentView.frame)-55, 22)];
        nextLocation1Label.text=@"";
        nextLocation1Label.textAlignment=NSTextAlignmentLeft;
        nextLocation1Label.font=[UIFont systemFontOfSize:14];
        nextLocation1Label.textColor=[UIColor colorWithHexString:@"#2e2e2e"];
        self.otherNextActivityTimeLabel=nextLocation1Label;
        [nextSelectLocationView addSubview:nextLocation1Label];
        
        
        UIView *selectUiview2=[[UIView alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(selectUiview1.frame)+68, 15, 15)];
        UIImageView *select2mageView =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 15, 15)];
        select2mageView.image=[UIImage imageNamed:@"ask_pass_icon"];
        [selectUiview2 addSubview:select2mageView];
        [nextSelectLocationView addSubview:selectUiview2];
        
        
        UILabel *nextActivityDes2Label = [[UILabel alloc]initWithFrame:CGRectMake(45,CGRectGetMaxY(nextLocation1Label.frame)+30, CGRectGetWidth(self.contentView.frame)-55, 22)];
        nextActivityDes2Label.text=@"我想在 : 12：00-18：00年电影";
        nextActivityDes2Label.textAlignment=NSTextAlignmentLeft;
        nextActivityDes2Label.font=[UIFont systemFontOfSize:14];
        nextActivityDes2Label.textColor=[UIColor colorWithHexString:@"#2e2e2e"];
        
        [nextSelectLocationView addSubview:nextActivityDes2Label];
        self.myNextActivityDesLabel=nextActivityDes2Label;
        
        UILabel *nextLocation2Label = [[UILabel alloc]initWithFrame:CGRectMake(45,CGRectGetMaxY(nextActivityDes2Label.frame)+10, CGRectGetWidth(self.contentView.frame)-55, 22)];
        nextLocation2Label.text=@"地址 : 山西大学东校区东门";
        nextLocation2Label.textAlignment=NSTextAlignmentLeft;
        nextLocation2Label.font=[UIFont systemFontOfSize:14];
        nextLocation2Label.textColor=[UIColor colorWithHexString:@"#2e2e2e"];
        
        [nextSelectLocationView addSubview:nextLocation2Label];
        self.myNextActivityTimeLabel=nextLocation2Label;
        self.nextSelectLocationView = nextSelectLocationView;
        self.nextSelectLocationView.alpha=0;
        [self.contentView addSubview:nextSelectLocationView];
        
        //默认选中第一个
        [SINACircularBeadUtils makeCircularView:select2mageView];
        [SINACircularBeadUtils makeCircularView:selectImageView];
        select2mageView.image=nil;
        select2mageView.backgroundColor=[UIColor colorWithHexString:@"#eeeeee"];
        
        [[SINAUiviewClickLiserner alloc]viewClickFunction:selectUiview1 andWithBlick:^(UIView *view) {
            select2mageView.image=nil;
            select2mageView.backgroundColor=[UIColor colorWithHexString:@"#eeeeee"];
            selectImageView.image=[UIImage imageNamed:@"ask_pass_icon"];
           
            
            self.activitySelectStartTime=self.model.activityStartTime;
            self.activitySelectEndTime=self.model.activityStopTime;
            self.activitySelectLocation=self.model.activityLocation;
        }];
        
        [[SINAUiviewClickLiserner alloc]viewClickFunction:selectUiview2 andWithBlick:^(UIView *view) {
            selectImageView.image=nil;
            selectImageView.backgroundColor=[UIColor colorWithHexString:@"#eeeeee"];
            
            select2mageView.image=[UIImage imageNamed:@"ask_pass_icon"];
            
            self.activitySelectStartTime=self.coursItemModel.activityStartTime;
            self.activitySelectEndTime=self.coursItemModel.activityStopTime;
            self.activitySelectLocation=self.coursItemModel.activityLocation;
        }];
        
    }
    return self;
}


- (UIView *)contentView
{
    if (!_contentView) {
        _contentView = [[UIView alloc]initWithFrame:CGRectMake(37,120, mainW-74,mainH-230)];
        [_contentView setBackgroundColor:[UIColor whiteColor]];
    }
    return _contentView;
}
//显示选择器
- (void)show
{
    WeakSelf;
    
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    [self setCenter:[UIApplication sharedApplication].keyWindow.center];
    [[UIApplication sharedApplication].keyWindow bringSubviewToFront:self];
    
    
    CGRect frame =  self.contentView.frame;
    frame.origin.y = mainH;
    self.contentView.frame = frame;
    frame.origin.y = 120;
    [UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        [weakSelf.layer setOpacity:1.0];
        weakSelf.contentView.frame = frame;
        
    } completion:^(BOOL finished) {
        [weakSelf loadingDetaileFunction];
    }];
    
}

//移除选择器
- (void)disMiss
{
    
    CGRect frame =  self.contentView.frame;
    frame.origin.y += self.contentView.frame.size.height;
    [UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        [self.layer setOpacity:0.0];
        self.contentView.frame = frame;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
    
}








//设置显示数据 
-(void)setModel:(SINASINAStuHomeCoursItemModel2 *)model{
    _model = model;
    
    NSString * activityTitle = self.coursItemModel.activityTitle;
    if (activityTitle==nil||activityTitle.length==0||[activityTitle isEqualToString:@"(null)"]) {
        activityTitle = self.coursItemModel.activityDes;
    }
    self.activityDes = activityTitle;
    
    self.activitySelectStartTime=self.model.activityStartTime;
    self.activitySelectEndTime=self.model.activityStopTime;
    self.activitySelectLocation=self.model.activityLocation;
    
    __block typeof(self) bself = self;
    
    [self.userTitleImageView  sd_setImageWithURL:[NSURL URLWithString:model.userTitleImageUrl] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        
    }];
    
    [[SINAUiviewClickLiserner alloc]viewClickFunction:self.cancleUILabel andWithBlick:^(UIView *view) {
        //对比时间 如果 时间地址一样 直接发起邀请请求 如果不一样 进行下一步选择时间与地点
        NSString *myStartTimeString = bself.coursItemModel.activityStartTime;
        NSString *myStopTimeString = bself.coursItemModel.activityStopTime;
        
        NSString *otherStartTimeString = bself.model.activityStartTime;
        NSString *otherStopTimeString = bself.model.activityStopTime;
        if(self.pageType==0){
            if (bself.currentStatue==0) {
                if ([myStartTimeString isEqualToString:otherStartTimeString]&&[myStopTimeString isEqualToString:otherStopTimeString]) {
                    //相同
                    [bself commitDataFunction];
                } else {
                    bself.nextSelectLocationView.hidden=NO;
                    //不相同
                    [UIView animateWithDuration:0.3f animations:^{
                        bself.userNameLabel.alpha=0;
                        bself.userClassLabel.alpha=0;
                        bself.activityDesLabel.alpha=0;
                        bself.activityLocationLabel.alpha=0;
                        bself.isActivityLabel.alpha=0;
                        bself.currentStatue=1;
                        bself.nextSelectLocationView.alpha=1;
                    } completion:^(BOOL finished) {
                        
                         NSString *dexs = [NSString stringWithFormat:@"%@ - %@",[SINACalendarUtils getDateStringWithTimeStr:self.model.activityStartTime andFormat:@"HH:mm"],[SINACalendarUtils getDateStringWithTimeStr:self.model.activityStopTime andFormat:@"HH:mm"]];
                        
                        NSString *activityDes=@"";
                        if (bself.userSex==1) {
                            activityDes=[NSString stringWithFormat:@"他想在：%@ %@ ",dexs,self.activityDes];
                        } else {
                            activityDes=[NSString stringWithFormat:@"她想在：%@ %@ ",dexs,self.activityDes];
                        }
                        bself.otherNextActivityDesLabel.text = activityDes;
                        bself.otherNextActivityTimeLabel.text = [NSString stringWithFormat:@"地址：%@" ,self.model.activityLocation];
                        
                        
                        NSString *mydexs = [NSString stringWithFormat:@"%@ - %@",[SINACalendarUtils getDateStringWithTimeStr:self.coursItemModel.activityStartTime andFormat:@"HH:mm"],[SINACalendarUtils getDateStringWithTimeStr:self.coursItemModel.activityStopTime andFormat:@"HH:mm"]];
                        activityDes=[NSString stringWithFormat:@"我想在：%@ %@ ",mydexs,self.activityDes];
                        
                        bself.myNextActivityDesLabel.text = activityDes;
                        bself.myNextActivityTimeLabel.text = [NSString stringWithFormat:@"地址：%@" ,self.coursItemModel.activityLocation];
                        
                    }];
                }
            }else{
                [bself commitDataFunction];
            }
        }else{
            [bself agreeTeamFunction];
        }
    }];
    
    [[SINAUiviewClickLiserner alloc]viewClickFunction:self.selectUILabel andWithBlick:^(UIView *view) {
        
        
        
        if (bself.pageType==0) {
            //发起邀请
            if (bself.currentStatue==1) {
                //上一步
                [UIView animateWithDuration:0.3f animations:^{
                    bself.userNameLabel.alpha=1;
                    bself.userClassLabel.alpha=1;
                    bself.activityDesLabel.alpha=1;
                    bself.activityLocationLabel.alpha=1;
                    bself.isActivityLabel.alpha=1;
                    bself.nextSelectLocationView.alpha=0;
                    bself.currentStatue=0;
                } completion:^(BOOL finished) {
                    bself.nextSelectLocationView.hidden=YES;
                }];
            } else {
                //不相同
                [bself disMiss];
            }
            
        } else {
            //拒绝同意请求
            [bself refuseTeamFunction];
        }
    }];
    
}


//提交数据
-(void)commitDataFunction{
    if (self.pageType==0) {
        //发起邀请
        DLog(@"发起邀请");
        [self activityTeamFunction];
    } else {
        //同意请求
        DLog(@"同意请求");
    }
}
//拒绝请求
-(void)refuseTeamFunction{
    DLog(@"拒绝请求");
    [self accesActivityTeamFunction:2];
}
//同意请求
-(void)agreeTeamFunction{
    DLog(@"同意请求");
    [self accesActivityTeamFunction:1];
}
//接收邀请或者 拒绝邀请
//1 同意
//2 拒绝
-(void)accesActivityTeamFunction:(NSInteger) type{
    
    WeakSelf;
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    
    if (self.model==nil||self.model.activityUid==nil||[self.model.activityUid isEqualToString:@""]) {
        WISAlertView *alertView =  [[WISAlertView alloc]initWithTitle:@"提示" message:@"活动信息异常" sureBtn:@"确定" cancleBtn:nil];
        alertView.resultIndex = ^(NSInteger index) {
            [weakSelf disMiss];
        };
        [alertView showXLAlertView];
        return;
    }
    
    //活动的uuid
    [dict setObject:self.model.activityUid forKey:@"uuid"];
    //状态
    [dict setObject:[NSString stringWithFormat:@"%ld",(long)type] forKey:@"accept"];
    
    NSMutableDictionary *dict2 = [[NSMutableDictionary alloc]init];
    [dict2 setObject:[SINAHttpRequestUtils encodeDicParams:dict] forKey:@"sj"];
   
    [CXAFNHttpRequestUtils httpPostRequest:[NSString stringWithFormat:@"%@%@",baseUrl,userAcceptActivityTeamUrl] withParamters:dict2 success:^(id responseData) {
        NSString *code = responseData[@"code"];
        
        if ([code isEqualToString:@"1000"]) {
            DLog(@"发起邀请成功");
            NSString *message =@"请求成功";
            WISAlertView *alertView =  [[WISAlertView alloc]initWithTitle:@"提示" message:message sureBtn:@"确定" cancleBtn:nil];
            alertView.resultIndex = ^(NSInteger index) {
                //创建通知
                NSNotification *notification =[NSNotification notificationWithName:@"stuActivityAddFindOther" object:nil userInfo:dict];
                // 通过 通知中心 发送 通知
                [[NSNotificationCenter defaultCenter] postNotification:notification];
                
                [weakSelf disMiss];
            };
            [alertView showXLAlertView];
            
            
        
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.2*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                
                //创建通知
                NSNotification *notification =[NSNotification notificationWithName:@"stuActivityAddFindOther" object:nil userInfo:dict];
                // 通过 通知中心 发送 通知
                [[NSNotificationCenter defaultCenter] postNotification:notification];
                [alertView dismissXLAlertView];
                
                [weakSelf disMiss];
                
            });
        }else{
            DLog(@"发起邀请验证失败");
            NSString *message =@"请求验证失败";
            WISAlertView *alertView =  [[WISAlertView alloc]initWithTitle:@"提示" message:message sureBtn:@"确定" cancleBtn:nil];
            [alertView showXLAlertView];
            
            
        }
        
    } failure:^(NSError *error, NSInteger errCode) {
        DLog(@"发起邀请失败 网络异常");
        NSString *message =@"请求失败 网络异常";
        WISAlertView *alertView =  [[WISAlertView alloc]initWithTitle:@"提示" message:message sureBtn:@"确定" cancleBtn:nil];
        [alertView showXLAlertView];
    }];
}

//发起邀请
-(void)activityTeamFunction{
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  
    //发起邀请人的uuid
    [dict setObject:[[SINACommonUserHelper share] getUserModel].userUid forKey:@"studentuuid"];
    //邀请目标人id
    [dict setObject:self.model.activityUid forKey:@"organizeuuid"];
    //发起人发的活动id Integer followerorganizeid
    [dict setObject:self.coursItemModel.activityUid forKey:@"followerorganizeuuid"];
    
    [dict setObject:self.activitySelectStartTime forKey:@"applystarttime"];
    [dict setObject:self.activitySelectEndTime forKey:@"applyendtime"];
    [dict setObject:self.activitySelectLocation forKey:@"applyaddress"];
    
    NSMutableDictionary *dict2 = [[NSMutableDictionary alloc]init];
    [dict2 setObject:[SINAHttpRequestUtils encodeDicParams:dict] forKey:@"sj"];
    WeakSelf;
    [CXAFNHttpRequestUtils httpPostRequest:[NSString stringWithFormat:@"%@%@",baseUrl,userActivityTeamUrl] withParamters:dict2 success:^(id responseData) {
        NSString *code = responseData[@"code"];
       
        if ([code isEqualToString:@"1000"]) {
            DLog(@"发起邀请成功");
            NSString *message =@"发起成功";
            WISAlertView *alertView =  [[WISAlertView alloc]initWithTitle:@"提示" message:message sureBtn:@"确定" cancleBtn:nil];
            alertView.resultIndex = ^(NSInteger index) {
                //创建通知
                NSNotification *notification =[NSNotification notificationWithName:@"stuActivityAddFindOther" object:nil userInfo:dict];
                // 通过 通知中心 发送 通知
                [[NSNotificationCenter defaultCenter] postNotification:notification];
                
                 [weakSelf disMiss];
            };
            [alertView showXLAlertView];
        
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                
                [alertView dismissXLAlertView];
                
            });
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.2*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                
                [weakSelf disMiss];
                
            });
        }else if ([code isEqualToString:@"1012"]) {
            NSString *message =@"已发起过邀请了";
            WISAlertView *alertView =  [[WISAlertView alloc]initWithTitle:@"提示" message:message sureBtn:@"确定" cancleBtn:nil];
            [alertView showXLAlertView];
        }else{
            DLog(@"发起邀请验证失败");
            NSString *message =@"发起邀请验证失败";
            WISAlertView *alertView =  [[WISAlertView alloc]initWithTitle:@"提示" message:message sureBtn:@"确定" cancleBtn:nil];
            [alertView showXLAlertView];
             
            
        }
        
    } failure:^(NSError *error, NSInteger errCode) {
        DLog(@"发起邀请失败 网络异常");
        NSString *message =@"发起邀请失败 网络异常";
        WISAlertView *alertView =  [[WISAlertView alloc]initWithTitle:@"提示" message:message sureBtn:@"确定" cancleBtn:nil];
        [alertView showXLAlertView];
    }];
}

//加载用户详情
-(void)loadingDetaileFunction{
    
    NSString *userUid=self.model.activityUserUid;
    WeakSelf;
    [CXAFNHttpRequestUtils httpGetRequest:[NSString stringWithFormat:@"%@%@?uuid=%@",baseUrl,userInformationUrl,userUid]  success:^(id responseData) {
        NSString *code = responseData[@"code"];
        
        NSString *universityname=@"无";
        NSString *realname=@"无";
        NSString *collname=@"无";
        NSString *classifyname=@"无";
        
        NSString *activityDes=@"无";
        NSString *isTeam=@"无";
        NSString *location=@"无";
        
        if ([code isEqualToString:@"1000"]) {
            NSDictionary *personInfromation = responseData[@"content"];
            universityname=personInfromation[@"universityname"];
            realname=personInfromation[@"realname"];
            collname=personInfromation[@"collname"];
            classifyname=personInfromation[@"classifyname"];
            NSString *sex=personInfromation[@"sex"];
            
            NSString *dexs = [NSString stringWithFormat:@"%@ - %@",[SINACalendarUtils getDateStringWithTimeStr:self.model.activityStartTime andFormat:@"HH:mm"],[SINACalendarUtils getDateStringWithTimeStr:self.model.activityStopTime andFormat:@"HH:mm"]];
            weakSelf.userSex = [sex integerValue];
            if ([sex integerValue]==1) {
                activityDes=[NSString stringWithFormat:@"他想在：%@ %@ ",dexs,self.activityDes];
                isTeam=[NSString stringWithFormat:@"是否向他发起组队邀请"];
            } else {
                
                activityDes=[NSString stringWithFormat:@"她想在：%@ %@ ",dexs,self.activityDes];
                isTeam=[NSString stringWithFormat:@"是否向她发起组队邀请"];
            }
            
            location = [NSString stringWithFormat:@"地址：%@" ,self.model.activityLocation];
            
        }else{
            
            universityname=@"加载失败 请重新进入";
            realname=@"加载失败 请重新进入";
            collname=@"加载失败 请重新进入";
            classifyname=@"加载失败 请重新进入";
            location=@"加载失败 请重新进入";
        }
        
        weakSelf.userNameLabel.text = realname;
        weakSelf.userNameLabel.backgroundColor=[UIColor clearColor];
        
        weakSelf.userClassLabel.text = collname;
        weakSelf.userClassLabel.backgroundColor=[UIColor clearColor];
        
        weakSelf.activityDesLabel.text = activityDes;
        weakSelf.activityDesLabel.backgroundColor=[UIColor clearColor];
        
        weakSelf.activityLocationLabel.text = location;
        weakSelf.activityLocationLabel.backgroundColor=[UIColor clearColor];
        
        weakSelf.isActivityLabel.text = isTeam;
        weakSelf.isActivityLabel.backgroundColor=[UIColor clearColor];
        
        weakSelf.cancleUILabel.backgroundColor=baseSelectColor;
        
    } failure:^(NSError *error, NSInteger errCode) {
        
        NSString *universityname=@"无";
        NSString *realname=@"无";
        NSString *collname=@"无";
        NSString *classifyname=@"无";
        
        NSString *activityDes=@"无";
        NSString *isTeam=@"无";
        NSString *location=@"无";
        
        
        universityname=@"加载失败 请重新进入";
        realname=@"加载失败 请重新进入";
        collname=@"加载失败 请重新进入";
        classifyname=@"加载失败 请重新进入";
        location=@"加载失败 请重新进入";
        weakSelf.userNameLabel.text = realname;
        weakSelf.userClassLabel.text = collname;
        weakSelf.activityDesLabel.text = activityDes;
        weakSelf.activityLocationLabel.text = location;
        weakSelf.isActivityLabel.text = isTeam;
        
    }];
}

@end
